package com.catemanagement.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class Bill implements Serializable {

    private static final long serialVersionUID = -2158575883825939105L;

    private Long id;

    private String tableName;

    private Float totalPrice;

    private String sendBy;

    private Date sendTime;

    private Integer printStatus;

    private Date printTime;

    private List<BillMenu> billMenuList = new ArrayList<BillMenu>();

    /**
     * 恢复初始状态，重新点菜
     */
    public void reset() {
        id = null;
        tableName = null;
        sendTime = null;
        printStatus = null;
        printTime = null;
        totalPrice = null;
        billMenuList.clear();
    }

    public void addBillMenu(BillMenu billMenu) {
        billMenu.setBillId(this.id);
        billMenu.setCount(1F);
        billMenuList.add(billMenu);

    }

    public boolean containsBillMenu(Long menuId) {
        for (BillMenu billMenu : billMenuList) {
            if (billMenu.getMenuId().equals(menuId)) {
                return true;
            }
        }
        return false;
    }

    public BillMenu findBillMenu(Long menuId) {
        for (BillMenu billMenu : billMenuList) {
            if (billMenu.getMenuId().equals(menuId)) {
                return billMenu;
            }
        }
        return null;
    }

    /**
     * 移除菜单.
     * 
     * @param menuId the menu id
     */
    public void removeBillMenu(Long menuId) {
        for (Iterator<BillMenu> iterator = billMenuList.iterator(); iterator.hasNext();) {
            BillMenu bm = iterator.next();
            if (bm.getMenuId().equals(menuId)) {
                iterator.remove();
                break;
            }
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getSendBy() {
        return sendBy;
    }

    public void setSendBy(String sendBy) {
        this.sendBy = sendBy;
    }

    public Date getSendTime() {
        return sendTime;
    }

    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }

    public Date getPrintTime() {
        return printTime;
    }

    public void setPrintTime(Date printTime) {
        this.printTime = printTime;
    }

    public Float getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Float totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Integer getPrintStatus() {
        return printStatus;
    }

    public void setPrintStatus(Integer printStatus) {
        this.printStatus = printStatus;
    }

    public List<BillMenu> getBillMenuList() {
        return billMenuList;
    }

    public void setBillMenuList(List<BillMenu> billMenuList) {
        this.billMenuList = billMenuList;
    }

    public Float calculateTotalPrice() {
        Float total = 0.0F;
        for (BillMenu billMenu : billMenuList) {
            total += billMenu.getPrice();
        }
        return total;
    }

    public String getTotalInfo() {
        if (billMenuList.isEmpty()) {
            return "还未点菜";
        }
        return "总计 ：" + calculateTotalPrice();
    }

}
